package com.wwj.netty.bio.data;

import java.io.*;
import java.net.ServerSocket;
import java.net.Socket;

/**
 *
 * @author wuweijun
 * @date 2018/11/12
 */
public class Server {
    //默认服务端端口
    private static Integer DEFAULT_SERVER_PORT=8080;

    //服务端启动
    public static void start(){
        ServerSocket serverSocket=null;

        try {
            //兼听端口
            serverSocket=new ServerSocket(DEFAULT_SERVER_PORT);
            while (true){
                Socket socket=serverSocket.accept();
                new Thread(new ServerHandler(socket)).start();
            }

        } catch (IOException e) {
            e.printStackTrace();
        }finally {
            if(serverSocket!=null){
                try {
                    serverSocket.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
    }
}
